home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
filutil
/
uudx278d.zip
/
DEFISHX.DIF
next >
Wrap
Text File
|
1993-03-06
|
10KB
|
466 lines
--- ..\uudx\uudx.c Fri Feb 26 22:22:12 1993
+++ defishx.c Fri Feb 26 22:16:38 1993
@@ -1,11 +1,11 @@
/*
- * uudx - extractor from uuencoded files
+ * defishx - extractor from fishencoded files
*
* Written by AssistantIO
*/
-#define COMMAND "uudx"
-#define VERSION "ver. 2.78"
+#define COMMAND "defishx"
+#define VERSION "ver. 0.06"
#include <stdio.h>
#include <ctype.h>
@@ -130,6 +130,12 @@
static void uudx(FILE *fh_i);
static char *jstrupr(char *p);
static int decode_begin(char *inbuf, int *mode, char *file_name);
+static int xdecode(int type, char *inbuf, char *outbuf);
+static int decode2(char *inbuf, char *outbuf);
+static int decode3(char *inbuf, char *outbuf);
+static void initialize_hash(void);
+static int search_table(int c1, int c2);
+static void *xmalloc(int size);
static int check_file(char *fname);
static int file_cmp(char *fname1, char *fname2);
static int decode(char *ibuf, char *obuf);
@@ -233,6 +239,8 @@
signal(SIGINT, sig_int_handler);
#endif
+ initialize_hash();
+
if (optind >= argc && isatty(fileno(stdin)) == 0) {
fp = stdin;
fprintf(stderr, "Decoding from %s ...\n",
@@ -329,6 +337,7 @@
char *fname, *p, *s;
int l, i;
int long_line, newline;
+ int type;
#if MSDOS
setmode(fileno(fh_i), O_BINARY);
@@ -370,7 +379,7 @@
if (newline
&& !long_line
&& strncmp(inbuf, "begin", 5) == 0
- && decode_begin(inbuf, &mode, file_name) > 0) {
+ && (type = decode_begin(inbuf, &mode, file_name)) > 0) {
if (nerror > 1L) {
fprintf(stderr, "[%ld] %s\n", line_no - 1, errbuf);
@@ -505,7 +514,7 @@
&& !tmp_off
&& newline
&& !long_line
- && (n = decode(inbuf, outbuf)) > 0) {
+ && (n = xdecode(type, inbuf, outbuf)) > 0) {
if (nerror > 1L) {
fprintf(stderr, "[%ld] %s\n", line_no - 1, errbuf);
@@ -580,6 +589,7 @@
decode_begin(char *inbuf, int *mode, char *file_name)
{
char *p;
+ int type;
p = inbuf;
if (strncmp(p, "begin ", 6) != 0) {
@@ -588,19 +598,33 @@
p += 6;
while (*p == ' ') {
p++;
- }
- if (*p < '0' || *p > '7') {
- return 0;
}
- *mode = 0;
- while (*p >= '0' && *p <= '7') {
- *mode = *mode * 8 + *p - '0';
+ if (strncmp(p, "4649 ", 5) == 0) {
+ type = 2;
+ *mode = 0644;
+ p += 5;
+ } else if (strncmp(p, "86~ ", 4) == 0) {
+ type = 3;
+ *mode = 0644;
+ p += 4;
+ } else if (strncmp(p, "24~ ", 4) == 0) {
+ type = 2;
+ *mode = 0644;
+ p += 4;
+ } else if (*p >= '0' && *p <= '7') {
+ type = 1;
+ *mode = 0;
+ while (*p >= '0' && *p <= '7') {
+ *mode = *mode * 8 + *p - '0';
+ p++;
+ }
+ if (*p != ' ') {
+ return 0;
+ }
p++;
- }
- if (*p != ' ') {
+ } else {
return 0;
}
- p++;
while (*p == ' ') {
p++;
}
@@ -618,7 +642,323 @@
return 0;
}
}
- return 1;
+ return type;
+}
+
+static int
+xdecode(int type, char *inbuf, char *outbuf)
+{
+ int ret;
+
+ switch (type) {
+ case 1:
+ ret = decode(inbuf, outbuf);
+ break;
+ case 2:
+ ret = decode2(inbuf, outbuf);
+ break;
+ case 3:
+ ret = decode3(inbuf, outbuf);
+ break;
+ default:
+ fprintf(stderr, "xdecode: type = %d\n", type);
+ cant("happen", "type", 1);
+ /* NOTREACHED */
+ }
+
+ return ret;
+}
+
+static int
+decode2(char *ibuf, char *obuf)
+{
+ int n, code1, code2;
+ char *ip, *op;
+
+ ip = ibuf;
+ op = obuf;
+
+ n = 0;
+ while (*ip != '\0') {
+ if ((code1 = search_table(ip[0], ip[1])) < 0) {
+ return -1;
+ }
+ if ((code2 = search_table(ip[2], ip[3])) < 0) {
+ return -1;
+ }
+ ip += 4;
+ *op++ = (char) (code1 * 64 + code2);
+ n++;
+ }
+
+ return n;
+}
+
+static int
+decode3(char *ibuf, char *obuf)
+{
+ int len, n;
+ int code1, code2, code3, code4;
+ char *ip, *op;
+
+ len = strlen(ibuf);
+ ip = ibuf;
+ op = obuf;
+
+ n = 0;
+ while (len >= 8) {
+ if ((code1 = search_table(ip[0], ip[1])) < 0) {
+ return -1;
+ }
+ if ((code2 = search_table(ip[2], ip[3])) < 0) {
+ return -1;
+ }
+ if ((code3 = search_table(ip[4], ip[5])) < 0) {
+ return -1;
+ }
+ if ((code4 = search_table(ip[6], ip[7])) < 0) {
+ return -1;
+ }
+ len -= 8;
+ ip += 8;
+ *op++ = (char) (code1 * 4 + (code2 & 0x30) / 16);
+ *op++ = (char) ((code2 * 16 + (code3 & 0x3c) / 4) & 255);
+ *op++ = (char) ((code3 * 64 + code4) & 255);
+ n += 3;
+ }
+ if (len == 6) {
+ if ((code1 = search_table(ip[0], ip[1])) < 0) {
+ return -1;
+ }
+ if ((code2 = search_table(ip[2], ip[3])) < 0) {
+ return -1;
+ }
+ if ((code3 = search_table(ip[4], ip[5])) < 0) {
+ return -1;
+ }
+ len -= 6;
+ ip += 6;
+ *op++ = (char) (code1 * 4 + code2 / 16);
+ *op++ = (char) ((code2 * 16 + code3 / 4) & 255);
+ n += 2;
+ } else if (len == 4) {
+ if ((code1 = search_table(ip[0], ip[1])) < 0) {
+ return -1;
+ }
+ if ((code2 = search_table(ip[2], ip[3])) < 0) {
+ return -1;
+ }
+ len -= 4;
+ ip += 4;
+ *op++ = (char) (code1 * 4 + code2 / 16);
+ n += 1;
+ } else if (len != 0) {
+ return -1;
+ }
+
+ return n;
+}
+
+typedef struct {
+ char *fish_char;
+ int fish_value;
+} fish_t;
+
+fish_t fish_table[] = {
+ { "ê▒", 0x00, },
+ { "ê╝", 0x01, },
+ { "ê±", 0x02, },
+ { "ëV", 0x03, },
+ { "èé", 0x04, },
+ { "èÅ", 0x05, },
+ { "ï¢", 0x06, },
+ { "î~", 0x07, },
+ { "î∩", 0x08, },
+ { "ì°", 0x09, },
+ { "ÄI", 0x0a, },
+ { "ÄL", 0x0b, },
+ { "æΓ", 0x0c, },
+ { "ÆL", 0x0d, },
+ { "òh", 0x0e, },
+ { "ò⌐", 0x0f, },
+ { "ûÄ", 0x10, },
+ { "ûÉ", 0x11, },
+ { "ÿk", 0x12, },
+ { "Θ╡", 0x13, },
+ { "Θ╢", 0x14, },
+ { "Θ╖", 0x15, },
+ { "Θ╕", 0x16, },
+ { "Θ╣", 0x17, },
+ { "Θ║", 0x18, },
+ { "Θ╗", 0x19, },
+ { "Θ╝", 0x1a, },
+ { "Θ╜", 0x1b, },
+ { "Θ╛", 0x1c, },
+ { "Θ┐", 0x1d, },
+ { "Θ└", 0x1e, },
+ { "Θ┴", 0x1f, },
+ { "Θ┬", 0x20, },
+ { "Θ├", 0x21, },
+ { "Θ─", 0x22, },
+ { "Θ┼", 0x23, },
+ { "Θ╞", 0x24, },
+ { "Θ╟", 0x25, },
+ { "Θ╚", 0x26, },
+ { "Θ╔", 0x27, },
+ { "Θ╩", 0x28, },
+ { "Θ╦", 0x29, },
+ { "Θ╠", 0x2a, },
+ { "Θ═", 0x2b, },
+ { "Θ╬", 0x2c, },
+ { "Θ╧", 0x2d, },
+ { "Θ╨", 0x2e, },
+ { "Θ╤", 0x2f, },
+ { "Θ╥", 0x30, },
+ { "Θ╙", 0x31, },
+ { "Θ╘", 0x32, },
+ { "Θ╒", 0x33, },
+ { "Θ╓", 0x34, },
+ { "Θ╫", 0x35, },
+ { "Θ╪", 0x36, },
+ { "Θ┘", 0x37, },
+ { "Θ┌", 0x38, },
+ { "Θ█", 0x39, },
+ { "Θ▄", 0x3a, },
+ { "Θ▌", 0x3b, },
+ { "Θ▐", 0x3c, },
+ { "Θ▀", 0x3d, },
+ { "Θα", 0x3e, },
+ { "Θß", 0x3f, },
+ { "ΘΓ", 0x40, },
+ { "Θπ", 0x41, },
+ { "ΘΣ", 0x42, },
+ { "Θσ", 0x43, },
+ { "Θµ", 0x44, },
+ { "Θτ", 0x45, },
+ { "üÅ", 0x00, },
+ { "üÉ", 0x01, },
+ { "üë", 0x02, },
+ { "üè", 0x03, },
+ { "ü`", 0x04, },
+ { "ü[", 0x05, },
+ { "üE", 0x06, },
+ { "âA", 0x07, },
+ { "âC", 0x08, },
+ { "âE", 0x09, },
+ { "âG", 0x0a, },
+ { "âI", 0x0b, },
+ { "âJ", 0x0c, },
+ { "âL", 0x0d, },
+ { "âN", 0x0e, },
+ { "âP", 0x0f, },
+ { "âR", 0x10, },
+ { "âT", 0x11, },
+ { "âV", 0x12, },
+ { "âX", 0x13, },
+ { "âZ", 0x14, },
+ { "â\", 0x15, },
+ { "â^", 0x16, },
+ { "â`", 0x17, },
+ { "âc", 0x18, },
+ { "âe", 0x19, },
+ { "âg", 0x1a, },
+ { "âi", 0x1b, },
+ { "âj", 0x1c, },
+ { "âk", 0x1d, },
+ { "âl", 0x1e, },
+ { "âm", 0x1f, },
+ { "ân", 0x20, },
+ { "âq", 0x21, },
+ { "ât", 0x22, },
+ { "âw", 0x23, },
+ { "âz", 0x24, },
+ { "â}", 0x25, },
+ { "â~", 0x26, },
+ { "âÇ", 0x27, },
+ { "âü", 0x28, },
+ { "âé", 0x29, },
+ { "âä", 0x2a, },
+ { "âå", 0x2b, },
+ { "âê", 0x2c, },
+ { "âë", 0x2d, },
+ { "âè", 0x2e, },
+ { "âï", 0x2f, },
+ { "âî", 0x30, },
+ { "âì", 0x31, },
+ { "âÅ", 0x32, },
+ { "âÆ", 0x33, },
+ { "âô", 0x34, },
+ { "â@", 0x35, },
+ { "âB", 0x36, },
+ { "âD", 0x37, },
+ { "âF", 0x38, },
+ { "âH", 0x39, },
+ { "âb", 0x3a, },
+ { "ââ", 0x3b, },
+ { "âà", 0x3c, },
+ { "âç", 0x3d, },
+ { "üJ", 0x3e, },
+ { "üK", 0x3f, },
+ { NULL, 0xff, },
+};
+
+#define HASH_KEY 255
+
+typedef struct _hash_t {
+ fish_t *fish;
+ struct _hash_t *next;
+} hash_t;
+
+static hash_t *hash_table[HASH_KEY + 1];
+
+static void
+initialize_hash(void)
+{
+ int i;
+ fish_t *fish;
+ hash_t **hash;
+
+ for (fish = fish_table; fish->fish_char != NULL; fish++) {
+ i = (fish->fish_char[0] ^ fish->fish_char[1]) & HASH_KEY;
+
+ hash = &hash_table[i];
+ while (*hash != NULL) {
+ hash = &((*hash)->next);
+ }
+ *hash = xmalloc(sizeof(hash_t));
+ (*hash)->fish = fish;
+ (*hash)->next = NULL;
+ }
+}
+
+static int
+search_table(int c1, int c2)
+{
+
+ int i;
+ hash_t *hash;
+
+ i = (c1 ^ c2) & HASH_KEY;
+
+ for (hash = hash_table[i]; hash != NULL; hash = hash->next) {
+ if ((char) c1 == hash->fish->fish_char[0]
+ && (char) c2 == hash->fish->fish_char[1]) {
+ return hash->fish->fish_value;
+ }
+ }
+ return -1;
+}
+
+static void *
+xmalloc(int size)
+{
+ void *p;
+
+ if ((p = malloc(size)) == NULL) {
+ fprintf(stderr, "%s: memory exhausted.\n", prog_name);
+ exit(1);
+ }
+ return p;
}
#if !HUMAN
--- ..\uudx\makefile Thu Dec 03 14:02:52 1992
+++ makefile Sat Dec 05 20:19:34 1992
@@ -1,5 +1,5 @@
#
-# Makefile for UUDX.EXE
+# Makefile for DEFISHX.EXE
#
MODEL = C
@@ -10,11 +10,11 @@
LDFLAGS = -A$(MODEL)
FOO = /link /st:0x2000
-PROGRAM = uudx.exe
-SRCS = uudx.c \
+PROGRAM = defishx.exe
+SRCS = defishx.c \
xargs1.c \
getopt.c
-OBJS = uudx.obj \
+OBJS = defishx.obj \
xargs1.obj \
getopt.obj